#include <node.h>
#include "src/rtk.h"
#define MAXSIZE 2048

namespace index {
	using namespace v8;
	using namespace std;

	RTK single;

	void GetNav(const FunctionCallbackInfo<Value>& args){
		Isolate* isolate = args.GetIsolate();
		if (!args[0]->IsString()){
			isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Parameter must be String.")));
        	return;
		}
		v8::String::Utf8Value param1(args[0]->ToString());
    	string s_param1 = string(*param1);
    	int res = single.GetNav((char*)s_param1.data());
		args.GetReturnValue().Set(Number::New(isolate, res));
	}

	void caculate(const FunctionCallbackInfo<Value>& args){
		Isolate* isolate = args.GetIsolate();
		if (!args[0]->IsString()){
			isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Parameter must be String.")));
        	return;
		}
		v8::String::Utf8Value param1(args[0]->ToString());
    	string s_param1 = string(*param1);
    	single.GetRovObs((char*)s_param1.data());
    	char result_single[MAXSIZE]="";
    	single.SinglePos(result_single);
		args.GetReturnValue().Set(String::NewFromUtf8(isolate, result_single));
	}

	void init(Local<Object> exports) {
		//解码星历
	  	NODE_SET_METHOD(exports, "setOneNav", GetNav);
	  	//解码流动站观测值
	  	NODE_SET_METHOD(exports, "caculate", caculate);
	}

	NODE_MODULE(index, init)
}